#!/usr/bin/env python
#-------------------------------------------------------------------------------
#   file menu_5.py
#   brief
#       ZetCode wxPython tutorial
#
#       This example creates a context menu
#
#       author: Jan Bodnar
#       website: www.zetcode.com
#       last modified: September 2011
#
#   $Id: $
#-------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
import wx

class MyPopupMenu(wx.Menu):
    
    def __init__(self, parent):
        super(MyPopupMenu, self).__init__()
        self.parent = parent
        mmi = wx.MenuItem(self, wx.NewId(), 'Minimize')
        self.AppendItem(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)
        cmi = wx.MenuItem(self, wx.NewId(), 'Close')
        self.AppendItem(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)

    def OnMinimize(self, e):
        self.parent.Iconize()

    def OnClose(self, e):
        self.parent.Close()
        

class Example(wx.Frame):
   
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 
        self.InitUI()
        
    def InitUI(self):
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.SetSize((250, 200))
        self.SetTitle('Context menu')
        self.Centre()
        self.Show(True)
        
    def OnRightDown(self, e):
        self.PopupMenu(MyPopupMenu(self), e.GetPosition())

#-------------------------------------------------------------------------------
#   Main entry point
#   - Init the application
#   - Run the main loop
#-------------------------------------------------------------------------------
def main():
    ex = wx.App()
    Example(None)
    ex.MainLoop()    


#-------------------------------------------------------------------------------
#   Run main (if main)
#-------------------------------------------------------------------------------
if __name__ == '__main__':
    main()

#
#   End: menu_5.py
#
